home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGSCAL / EXTMEM.LZH / XMEMTEST.C < prev    next >
Text File  |  1987-09-14  |  2KB  |  79 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <alloc.h>
  4. #include <dos.h>
  5.  
  6. #define BLOCKSIZE 16384
  7.  
  8. int ext_mem_present( void );
  9. unsigned get_size( void );
  10. unsigned long get_loc( void );
  11. unsigned copy( unsigned long source, unsigned long dest, unsigned nbytes );
  12.  
  13. char far *buf;
  14. unsigned long ext_org;
  15. unsigned ext_size;
  16. unsigned long buf_org;
  17.  
  18. void init( void )
  19. {
  20.     ext_org = get_loc();
  21.     printf( "Available extended memory begins at address %lX.\n", ext_org );
  22.  
  23.     ext_size = get_size();
  24.     printf( "Extended memory consists of %uK bytes,\n", ext_size );
  25.     ext_size -= (ext_org - 0x100000L) >> 10;
  26.     printf( "\twith %uK bytes available for use.\n\n", ext_size );
  27.  
  28.     if ( ext_size == 0 )
  29.         {
  30.         printf( "No external memory present.\n" );
  31.         exit(0);
  32.         }
  33.  
  34.     if ( (buf = farmalloc( BLOCKSIZE )) == 0L )
  35.         {
  36.         printf( "Unable to allocate buffer.\n" );
  37.         exit(0);
  38.         }
  39.  
  40.     buf_org = (unsigned long)FP_SEG(buf)*16L + (unsigned long)FP_OFF(buf);
  41. }
  42.  
  43. void main()
  44. {
  45. unsigned char far *ptr;
  46. int wrong = 0, right = 0;
  47. int i;
  48.  
  49.     init();
  50.  
  51.     for ( ptr = buf, i = 0; i < BLOCKSIZE; i++ )
  52.         *ptr++ = i & 0xFF;
  53.  
  54.     if ( ext_size < 16 )
  55.         {
  56.         printf( "Insufficient extended memory available.\n" );
  57.         exit(0);
  58.         }
  59.  
  60.     printf( "Copying buffer to extended memory\n" );
  61.     copy( buf_org, ext_org, BLOCKSIZE );
  62.  
  63.     printf( "Rewriting buffer contents\n" );
  64.     for( ptr = buf, i = 0; i < BLOCKSIZE; i++ )
  65.         *ptr++ = 0;
  66.  
  67.     printf( "Copying extended memory back to buffer\n" );
  68.     copy( ext_org, buf_org, BLOCKSIZE );
  69.  
  70.     printf( "Comparing copied buffer with original\n" );
  71.     for( ptr = buf, i = 0; i < BLOCKSIZE; i++ )
  72.         if ( *ptr++ != (i & 0xFF) )
  73.             wrong++;
  74.         else
  75.             right++;
  76.  
  77.     printf( "\tNumber wrong = %d\n\tNumber right = %d\n", wrong, right );
  78. }
  79.